import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n" +
  "nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==";

const privateKey =
  "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n" +
  "7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n" +
  "PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n" +
  "kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n" +
  "cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n" +
  "DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n" +
  "YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n" +
  "UP8iWi1Qw0Y=";

const publicTransmitKey =
  "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtQO+akuax3DmzZTKg0ic\n" +
  "SJfb4GMde90BqFKY5SISlmXQ2OghB22Qwg0uk3wrr4kpRlX5UDJkdLumH2p5FNpI\n" +
  "MRMamlw4Qw3cMXt4FGL92MyxFKznuVVqrSaohRqLArnoA4GmLRNZoA1Q4HxJHMif\n" +
  "1mxaUdx1pYu4sD0090J+uwe8InNo/ueWxl2GEtdCXTXuKmNsxlKST7PAXTFH1AJe\n" +
  "GOCFsip606f0UjDNvoGYZyUm3WgcENzhNNdNa9JuaruE95mlMFlb009b0gysRU9n\n" +
  "4AUdGu5WYLZkHJ0z0ukZOiNBYoM1x/WTXWZpK6UsOzGV+VyilTWD05hDz6roKUDM\n" +
  "dwIDAQAB";

// const externalTransmitKey =
//   "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApYF+gP5PMpAe3ydwA+XMJM" +
//   "wh8232Az8UJ5wW4hktbysdyh7nUiXJdd/hoQeVsFiV8QZkvBX0BeWFsjquU4p9Ixa8xz" +
//   "uaUrO/qS+l9bSNQ9u7DzqggUd2gH0vytei7OQiClUG24kQ4WZV8npPhJJKTY7+qWkjt1j" +
//   "5LvZyz747iWY8dqXnK4iwrDn3v8D9n1EvzUutYwDSL5qPlu/SXeWkpOVhsISUzp/dIjf8" +
//   "WS0F3zxvgdfAT3wH+3Y6cKkz4Kcgfzurr7c58KKyaZ6HBFI99yE616yO8lJo5C2HgGouoP" +
//   "T+YxiDB/yNejTN1c/FTB5L0adcd+Xh6lBHHwWvWPIaNwIDAQAB";

const externalTransmitKey =
  "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApYF+gP5PMpAe3ydwA+XMJMwh8232Az8UJ5wW4hktbysdyh7nUiXJdd/hoQeVsFiV8QZkvBX0BeWFsjquU4p9Ixa8xzuaUrO/qS+l9bSNQ9u7DzqggUd2gH0vytei7OQiClUG24kQ4WZV8npPhJJKTY7+qWkjt1j5LvZyz747iWY8dqXnK4iwrDn3v8D9n1EvzUutYwDSL5qPlu/SXeWkpOVhsISUzp/dIjf8WS0F3zxvgdfAT3wH+3Y6cKkz4Kcgfzurr7c58KKyaZ6HBFI99yE616yO8lJo5C2HgGouoPT+YxiDB/yNejTN1c/FTB5L0adcd+Xh6lBHHwWvWPIaNwIDAQAB";

// 本地加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 本地解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}

// 传输加密
export function encryptTransmit(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicTransmitKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 外部用户传输加密
export function encryptExternalUsers(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(externalTransmitKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}
